/<template>
  <div class="headPage">
    <div class="head">
      <input type="text" placeholder="请在这里输入" />
      <span>地图</span>
    </div>
    <div class="banner">
      <van-swipe class="my-swipe" :autoplay="3000" indicator-color="red">
        <van-swipe-item v-for="(item, index) in total" :key="index">
          <van-grid :column-num="5">
            <van-grid-item
              v-for="(value,i) in 10"
              :key="value"
              :icon="
                navList[index * 10 + i] ? navList[index * 0 + i].img : 'photo-o'
              "
              :text="navList[index * 10 + i] ? navList[index * 0 + i].title : ''"
            />
          </van-grid>
        </van-swipe-item>
      </van-swipe>
    </div>
    <div class="list">
      <ul>
        <li v-for="(item,index) in house" :key="index">
          <img :src="item.img" alt="">
          <div>
            <h3 @click="toDetail(item.id)">
              <span>{{item.title}}</span>
              <b :style="{background:colors[item.type]}">{{item.type}}</b>
            </h3>
            <h2>￥{{item.price}}元</h2>
            <p>{{item.text}}</p>
          </div>
        </li>
      </ul>
    </div>
  </div>
</template>

<script>
import axios from "axios";
export default {
  data() {
    return {
      navList: [],
      total: 0,
      house:[],
      colors:{
        '在售':'#f60',
        '预售':'#09f',
        '尾盘':'#0c0'
      }
    };
  },
  mounted() {
    axios.get("/navList").then((res) => {
      console.log(res.data);
      this.navList = res.data;
      this.total = Math.ceil(res.data.length / 10);
    });
    axios.get('/house').then(res=>{
      console.log(res.data);
      this.house=res.data
    })
  },
  methods:{
    toDetail(id){
      this.$router.push({
        path:'/detail',
        query:{id}
      })
    }
  }
};
</script>

<style lang='scss'>
.head {
  width: 100%;
  height: 50px;
  display: flex;
  justify-content: space-around;
  align-items: center;
  input {
    margin-left: 20px;
    width: 300px;
    height: 30px;
    border: none;
    background: #eee;
    text-indent: 1rem;
    border-radius: 5px;
  }
}
.banner {
  .my-swipe .van-swipe-item {
    color: #fff;
    font-size: 20px;
    line-height: 150px;
    text-align: center;
    background-color: #39a9ed;
  }
}
.list{
  li{
    width: 100%;
    height: 150px;
    padding: 10px;
    display: flex;
    img{
      width: 100px;
      height: 100px;
      margin-right: 10px;
    }
    div{
      flex: 1;
    }
    h3{
      display: flex;
      justify-content: space-between;
      b{
        background: #f60;
      }
    }
  }
}
</style>